//
//  DestinationTblCell.m
//  RoadLine
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 RedFireNoodles. All rights reserved.
//

#import "DestinationTblCell.h"
#import "Singleton.h"
#import "NightManager.h"

#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@implementation DestinationTblCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGFloat width = [[UIScreen mainScreen] bounds].size.width;
        CGFloat height = [[UIScreen mainScreen] bounds].size.height;
        
        // cell的底层
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, width - 20, height * 100 / 667)];        view.tag = 10000;
        [self.contentView addSubview:view];
        self.contentView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
        view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"colorBlockImage"]];
        view.layer.cornerRadius = 15;
        view.clipsToBounds = YES;
        
        UIView *blackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width - 20, height * 100 / 667)];
        blackView.tag = 10005;
        [view addSubview:blackView];
        
        // 地点名Label
        self.nameLbl = [[UILabel alloc] init];
        [view addSubview:self.nameLbl];

        // 有多少人喜欢
        self.wish_to_goLbl = [[UILabel alloc] init];
        [view addSubview:self.wish_to_goLbl];
        
        // 有多少人去过
        self.visited_countLbl = [[UILabel alloc] init];
        [view addSubview:self.visited_countLbl];
        
        // 目的地图片
        self.destImgView = [[UIImageView alloc] init];
        [view addSubview:self.destImgView];
        self.destImgView.clipsToBounds = YES;
        self.destImgView.layer.cornerRadius = 10;
        
        [_destImgView release];
        [_visited_countLbl release];
        [_wish_to_goLbl release];
        [_nameLbl release];
        [view release];
//        [namebgView release];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat width = [[UIScreen mainScreen] bounds].size.width;
    CGFloat height = [[UIScreen mainScreen] bounds].size.height;
    
    self.nameLbl.frame = CGRectMake(WIDTH / 2 - 50, 0, WIDTH / 2, HEIGHT / 3);
    self.nameLbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:24];
    self.wish_to_goLbl.frame = CGRectMake(WIDTH / 2 - 50, HEIGHT / 3-5, WIDTH / 2, HEIGHT / 3);
    self.wish_to_goLbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    self.visited_countLbl.frame = CGRectMake(WIDTH / 2 - 50, HEIGHT * 2 / 3 - 20, WIDTH / 2, HEIGHT / 3);
    self.visited_countLbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    // 正方形  长宽一边高
    self.destImgView.frame = CGRectMake(10, height * 10 / 667, width * 150/ 667, width * 150 / 667);
    // 如果是3.5寸屏幕
    if (height == 480) {
        self.destImgView.frame = CGRectMake(10, height * 10 / 667, 60, 60);
    }
    if ([Singleton shareSingleton].isNight) {
        [[Singleton shareSingleton] loadNightModeInfoFormDisk];
    }
}
// 白天
- (void)setLightDayModel {
    [NightManager setBackgroundColorWithView:self.contentView];
    [NightManager setLabelColorWithLabel:self.nameLbl];
    [NightManager setLabelColorWithLabel:self.wish_to_goLbl];
    [NightManager setLabelColorWithLabel:self.visited_countLbl];
    self.contentView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    // 日间模式view的背景图
    UIView *view = [self.contentView viewWithTag:10000];
    view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"colorBlockImage"]];
    UIView*blackView = [view viewWithTag:10005];
    blackView.backgroundColor = [UIColor clearColor];
}
// 夜间
- (void)setNightDayModel {
    [NightManager setBackgroundColorWithView:self.contentView];
    [NightManager setLabelColorWithLabel:self.nameLbl];
    [NightManager setLabelColorWithLabel:self.wish_to_goLbl];
    [NightManager setLabelColorWithLabel:self.visited_countLbl];
    // 夜间模式view是的背景图
    UIView *view = [self.contentView viewWithTag:10000];
    view.backgroundColor = view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"colorBlockImage"]];
    UIView*blackView = [view viewWithTag:10005];
    blackView.backgroundColor = [UIColor colorWithRed:6/255.0 green:13/255.0 blue:29/255.0 alpha:0.5];
}

- (void)dealloc
{
    [_destImgView release];
    [_visited_countLbl release];
    [_wish_to_goLbl release];
    [_nameLbl release];
    [super dealloc];
}

@end
